{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#随机生成六个班的考试成绩，3门考试：Python、数学、语文。每个班50人\n",
    "import numpy as np\n",
    "class_1 = np.random.randint(0,101,size = (50,3))\n",
    "class_2 = np.random.randint(0,101,size = (50,3))\n",
    "class_3 = np.random.randint(0,101,size = (50,3))\n",
    "class_4 = np.random.randint(0,101,size = (50,3))\n",
    "class_5 = np.random.randint(0,101,size = (50,3))\n",
    "class_6 = np.random.randint(0,101,size = (50,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 24,  25,  63],\n",
       "       [ 11,  87,  73],\n",
       "       [ 41,  96,  21],\n",
       "       [  4,  80, 100],\n",
       "       [ 78,   3,  78],\n",
       "       [ 69,  44,  28],\n",
       "       [ 76,  71,  15],\n",
       "       [ 15,  19,   6],\n",
       "       [ 60,  83,  90],\n",
       "       [ 40,  69,  82],\n",
       "       [ 85,  32,  93],\n",
       "       [ 33,  89,  57],\n",
       "       [ 96,  89,  15],\n",
       "       [ 29,  94,  55],\n",
       "       [ 36,  54,  34],\n",
       "       [  2,  46,  69],\n",
       "       [ 18,  48,  83],\n",
       "       [  1,   0,  15],\n",
       "       [ 65,  78,  24],\n",
       "       [ 58,  49,  79],\n",
       "       [ 56,  96,  65],\n",
       "       [ 36, 100,  47],\n",
       "       [ 92,  38,  87],\n",
       "       [ 79,  31,  99],\n",
       "       [ 44,  75,   2],\n",
       "       [ 55,  62,  48],\n",
       "       [ 81,  83,  93],\n",
       "       [ 66,  71,  73],\n",
       "       [ 86,  92,  13],\n",
       "       [ 26,  21,  98],\n",
       "       [ 15,  21,  94],\n",
       "       [ 23,  95,  58],\n",
       "       [ 68,  32,  80],\n",
       "       [ 97,  73,  46],\n",
       "       [ 59,  45,  94],\n",
       "       [ 67,  90,  92],\n",
       "       [  8,  43,  66],\n",
       "       [ 49,  88,   4],\n",
       "       [ 94,  85,  83],\n",
       "       [  6,  65,  29],\n",
       "       [ 65,   4,  94],\n",
       "       [ 22,  95,  27],\n",
       "       [  8,  49,  41],\n",
       "       [ 88,  77,  82],\n",
       "       [  3,  92,  11],\n",
       "       [ 13,  57,  64],\n",
       "       [  2,  99,   0],\n",
       "       [ 51,  30,  20],\n",
       "       [ 83,   6,  28],\n",
       "       [ 16,  43,  27],\n",
       "       [ 28,  71,  67],\n",
       "       [ 68,  66, 100],\n",
       "       [  1,  50,  80],\n",
       "       [ 25,   8,  12],\n",
       "       [ 50,  20,  35],\n",
       "       [ 67,  65,  73],\n",
       "       [ 63,  44,  68],\n",
       "       [ 50,   1,   1],\n",
       "       [ 41,  62,  43],\n",
       "       [ 66,  75,   6],\n",
       "       [  0,  77,  71],\n",
       "       [ 25,  76,  93],\n",
       "       [ 81,  33,  92],\n",
       "       [ 64, 100,  93],\n",
       "       [ 99,  89,  44],\n",
       "       [ 45,  31,  46],\n",
       "       [ 73,  78,  53],\n",
       "       [ 93,  95,  39],\n",
       "       [ 86,  77,  88],\n",
       "       [ 84,  45,  14],\n",
       "       [ 98,  31,  72],\n",
       "       [ 13,  36,  13],\n",
       "       [ 49,  22,   3],\n",
       "       [ 99,  23,  44],\n",
       "       [ 48,  21,  74],\n",
       "       [ 61,  98,  79],\n",
       "       [ 94,  88,  65],\n",
       "       [ 58,  59,  53],\n",
       "       [ 30,  76,  75],\n",
       "       [ 91,  86,   6],\n",
       "       [ 12,  53,  60],\n",
       "       [ 63,  29,  24],\n",
       "       [ 65,  11,  44],\n",
       "       [ 66,  10,  24],\n",
       "       [ 27,   6,  62],\n",
       "       [  7,   1,  40],\n",
       "       [ 94,  74,  92],\n",
       "       [ 14,  65,  15],\n",
       "       [ 98,  79,  63],\n",
       "       [ 51,  15,  93],\n",
       "       [ 88,  90,  96],\n",
       "       [ 48,  10,  66],\n",
       "       [ 36,  42,  72],\n",
       "       [ 39,  57,  98],\n",
       "       [ 45,  13,  33],\n",
       "       [ 22,  82,   0],\n",
       "       [ 24,  72,  72],\n",
       "       [ 56,  45,  28],\n",
       "       [ 83,  62,   8],\n",
       "       [ 60,  74,  48],\n",
       "       [ 76,  98,  31],\n",
       "       [ 31,  20,  82],\n",
       "       [ 43,  28,  93],\n",
       "       [ 41,  65,  63],\n",
       "       [ 84,  26,   2],\n",
       "       [ 11,  16,  73],\n",
       "       [ 60,  91,  93],\n",
       "       [ 70,  58,  40],\n",
       "       [ 65,  63,  29],\n",
       "       [ 63,  33,  56],\n",
       "       [ 26,  76,  19],\n",
       "       [ 58,  42,  47],\n",
       "       [  9,  43,   7],\n",
       "       [ 75,  69,  73],\n",
       "       [ 87,  42,  25],\n",
       "       [ 95,  65,  30],\n",
       "       [  2,  71,  21],\n",
       "       [ 25,  22,  59],\n",
       "       [ 76,  10,  93],\n",
       "       [  3,  64,  49],\n",
       "       [ 40,  20,  78],\n",
       "       [ 58,  16,  62],\n",
       "       [ 97,  72,  36],\n",
       "       [ 29,  25,  75],\n",
       "       [ 11,  96,  16],\n",
       "       [  4,  85,  33],\n",
       "       [  5,  72,  77],\n",
       "       [ 94,  30, 100],\n",
       "       [ 85,  89,  99],\n",
       "       [ 82,  29,   6],\n",
       "       [  3,  38,  46],\n",
       "       [ 12,  34,  61],\n",
       "       [ 79,  10,  51],\n",
       "       [ 17,  56,  60],\n",
       "       [ 71,  42,  51],\n",
       "       [ 90,  49,  24],\n",
       "       [ 99,  90,  14],\n",
       "       [ 57,  88,  92],\n",
       "       [100,  94,  10],\n",
       "       [ 51,  36,  45],\n",
       "       [ 12,  70,  33],\n",
       "       [  0,  85,  67],\n",
       "       [  1,  43,  73],\n",
       "       [ 36,  97,  52],\n",
       "       [100,  53,  56],\n",
       "       [ 27,  26,  93],\n",
       "       [ 75,  38,  49],\n",
       "       [ 51,  11,  24],\n",
       "       [ 58,  55,  59],\n",
       "       [ 99,  57,  73],\n",
       "       [ 27,  93,  11],\n",
       "       [ 71,  87,  74],\n",
       "       [ 10,  60,  40],\n",
       "       [  7,  66,  75],\n",
       "       [ 44,  68,  63],\n",
       "       [ 61,  57,  77],\n",
       "       [  0,  98,  20],\n",
       "       [ 82,  27,  47],\n",
       "       [  2,  51,  10],\n",
       "       [ 74,  25,  73],\n",
       "       [ 66,  29,  13],\n",
       "       [  4,  10,  19],\n",
       "       [ 49,  83,  35],\n",
       "       [ 22,  42,  48],\n",
       "       [ 27,  84,  57],\n",
       "       [ 50,  38,  29],\n",
       "       [ 80,  29,  93],\n",
       "       [ 35,  98,  16],\n",
       "       [ 34,  86,   7],\n",
       "       [ 48,  60,  54],\n",
       "       [ 76,  14,  74],\n",
       "       [ 50,  10,  73],\n",
       "       [ 16,  67,   2],\n",
       "       [ 35,  68,  86],\n",
       "       [ 88,  39,  84],\n",
       "       [ 55,  81,   8],\n",
       "       [ 25,   3,  83],\n",
       "       [ 60,  55, 100],\n",
       "       [  3,  34,  81],\n",
       "       [ 46,  92,  73],\n",
       "       [ 99,  38,  45],\n",
       "       [ 85,  30,  32],\n",
       "       [ 92,  84,  57],\n",
       "       [ 28,  53,  87],\n",
       "       [ 56,  64,  39],\n",
       "       [ 20,  96,  37],\n",
       "       [ 85,  63,  31],\n",
       "       [ 63,  10,  75],\n",
       "       [ 73,  15,  20],\n",
       "       [ 28,  79,   4],\n",
       "       [ 31,  61,  33],\n",
       "       [ 30,   4,  88],\n",
       "       [ 11,  55,  32],\n",
       "       [  2,  45,  31],\n",
       "       [ 83,  37,  48],\n",
       "       [ 28,   6,  68],\n",
       "       [ 88,  62,  24],\n",
       "       [  8,  77,  51],\n",
       "       [ 40,  87,  38],\n",
       "       [ 51,  96,  30],\n",
       "       [ 86,  65,  70],\n",
       "       [ 40,   2,  73],\n",
       "       [ 66,  98,  31],\n",
       "       [ 36,   3,  28],\n",
       "       [ 85,  70,  14],\n",
       "       [ 36,  49,  85],\n",
       "       [ 33,   2,  95],\n",
       "       [ 31,  99,  68],\n",
       "       [ 15,   4,  33],\n",
       "       [ 69,  32,  73],\n",
       "       [  0,  25,   3],\n",
       "       [ 26,  36,  78],\n",
       "       [ 50,  89,  16],\n",
       "       [ 30,  61,  40],\n",
       "       [ 55,  50,  19],\n",
       "       [ 58,  36,  18],\n",
       "       [ 18,  61,  42],\n",
       "       [  0,  76,   7],\n",
       "       [ 25,  41,  11],\n",
       "       [ 98,  79,  82],\n",
       "       [  4,  52,  67],\n",
       "       [ 11,  35,  25],\n",
       "       [ 37,  50,  18],\n",
       "       [ 46,   8,  79],\n",
       "       [ 81,  53,  76],\n",
       "       [ 71,  21,  90],\n",
       "       [ 35,  20,  82],\n",
       "       [ 27,  61,  31],\n",
       "       [ 48,  81,  16],\n",
       "       [ 27,   9,  48],\n",
       "       [ 97,  59,  79],\n",
       "       [ 32,  80,   2],\n",
       "       [ 90,  34,  26],\n",
       "       [ 36,  88,  24],\n",
       "       [ 92,  56,  93],\n",
       "       [ 36,  82, 100],\n",
       "       [ 50,  71,  26],\n",
       "       [ 20,  84,  27],\n",
       "       [ 97,  63,  75],\n",
       "       [ 49,  63,  23],\n",
       "       [  6,  36,  35],\n",
       "       [ 43,   7,  25],\n",
       "       [ 89,  11,  36],\n",
       "       [ 52,  43,  28],\n",
       "       [ 89,  61,  29],\n",
       "       [ 71,  27,  34],\n",
       "       [ 26,  85,  16],\n",
       "       [ 88,  92,  76],\n",
       "       [ 47,  16,  37],\n",
       "       [ 43,  34,  45],\n",
       "       [ 48,  16,  26],\n",
       "       [ 34,  28,  69],\n",
       "       [ 19,  78,  77],\n",
       "       [ 69,  22,  99],\n",
       "       [ 71,  43,  26],\n",
       "       [ 13,  87,  45],\n",
       "       [ 84,  68,  31],\n",
       "       [ 64,  64,  98],\n",
       "       [ 89,   1,  23],\n",
       "       [ 89,  29,  98],\n",
       "       [ 96,   1,  24],\n",
       "       [ 88,  56,  39],\n",
       "       [ 85,  78,  65],\n",
       "       [ 44,  69,  83],\n",
       "       [ 33,  63,  70],\n",
       "       [ 33,  24,  61],\n",
       "       [ 39,  72,  17],\n",
       "       [ 25,  35,  44],\n",
       "       [ 32,  26,  68],\n",
       "       [ 30,  47,  37],\n",
       "       [ 48,  33,  79],\n",
       "       [ 70,  19,  30],\n",
       "       [ 63,  49,  40],\n",
       "       [ 51,  76,  44],\n",
       "       [ 98,  31,  72],\n",
       "       [ 43,  14,  17],\n",
       "       [ 53,  48,  46],\n",
       "       [ 86,  21,  54],\n",
       "       [  9, 100,  29],\n",
       "       [ 60,  77,  85],\n",
       "       [ 86,  70,  57],\n",
       "       [ 31,  52,  61],\n",
       "       [ 11,  17,  86],\n",
       "       [ 68,  38,  99],\n",
       "       [ 93,  56,  37],\n",
       "       [ 84,  97,  13],\n",
       "       [ 50,   6,   9],\n",
       "       [ 18,  66,  74],\n",
       "       [ 27,  30,  85],\n",
       "       [ 11,  65,  15],\n",
       "       [ 47,  18,   4],\n",
       "       [ 96,  76,  57],\n",
       "       [ 68,  63,  22],\n",
       "       [ 12,  99,  88],\n",
       "       [ 17,  19,  35],\n",
       "       [ 78,  77,  30],\n",
       "       [ 25,  51,  71],\n",
       "       [ 74,  81,  12],\n",
       "       [ 25,  87,  18],\n",
       "       [ 98,  31,  21]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将六个班的考试成绩进行合并得到score\n",
    "score = np.concatenate([class_1,class_2,class_3,class_4,class_5,class_6],axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1, 24, 25, 63],\n",
       "       [ 0, 11, 87, 73],\n",
       "       [ 1, 41, 96, 21],\n",
       "       ...,\n",
       "       [ 1, 74, 81, 12],\n",
       "       [ 1, 25, 87, 18],\n",
       "       [ 0, 98, 31, 21]])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#生成性别数组sex，水平叠加数组sex和score得到data\n",
    "sex = np.random.randint(0,2,size = (300,1))\n",
    "data = np.hstack((sex,score))\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.        , 31.31693977, 28.65724715, 29.04119128])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#分别计算男女各科成绩统计指标：最小值、最大值、平均分、中位数、标准差\n",
    "#男生各科成绩\n",
    "score_male = data[data[:,0]==0]\n",
    "#男生各科成绩最小值\n",
    "min_male = score_male.min(axis = 0)\n",
    "#男生各科成绩最大值\n",
    "max_male = score_male.max(axis = 0)\n",
    "#男生各科成绩平均分\n",
    "mean_male = score_male.mean(axis = 0)\n",
    "#男生各科成绩中位数\n",
    "median_male = np.median(score_male,axis = 0)\n",
    "#男生各科成绩标准差\n",
    "std_male = np.std(score_male,axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#女生各科成绩\n",
    "score_female = data[data[:,0]==1]\n",
    "#女生各科成绩最小值\n",
    "min_female = score_female.min(axis = 0)\n",
    "#女生各科成绩最大值\n",
    "max_female = score_female.max(axis = 0)\n",
    "#女生各科成绩平均分\n",
    "mean_female = score_female.mean(axis = 0)\n",
    "#女生各科成绩中位数\n",
    "median_female = np.median(score_female,axis = 0)\n",
    "#女生各科成绩标准差\n",
    "std_female = np.std(score_female,axis = 0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
